#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int add(int x, int y)
{
	return x + y;
}
int sub(int x, int y)
{
	return x - y;
}
int mul(int x, int y)
{
	return x * y;
}
int div(int x, int y)
{
	return x / y;
}

void menu(void)
{
	printf("**********************\n");
	printf("****1.add   2.sub ****\n");
	printf("****3.mul   4.div ****\n");
	printf("*********0.exit ******\n");
	printf("**********************\n");
}

void calc(int(*p)(int , int))
{
	int x, y = 0;
	printf("请输入两个操作数：>");
	scanf("%d%*c%d", &x, &y);
	int ret = (*p)(x, y);
	printf("ret = %d\n", ret);
}

int main()
{
	int input = 0;
	do
	{
		menu();
		printf("请选择:>");
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			calc(add);
			break;
		case 2:
			calc(sub);
			break;
		case 3:
			calc(mul);
			break;
		case 4:
			calc(div);
			break;
		case 0:
			printf("已退出!\n");
			break;
		default:
			printf("输入错误，请重新输入！\n");
			break;
		}
	} while (input);
	return 0;
}